from sqlalchemy import Column, Integer, String, CHAR, FLOAT, DECIMAL
from sqlalchemy.dialects.mysql import LONGTEXT
from datetime import datetime
from models.base import db


class orders_info(db.Base):
    __tablename__ = 'order_info'
    id = Column(Integer, autoincrement=True, primary_key=True)
    create_time = Column(Integer, default=0)
    order_number = Column(String(30), nullable=False, default='')
    title = Column(String(100), nullable=False, default='')
    author = Column(String(50), nullable=True)
    chars_sum = Column(Integer, default=0)
    similar_rate = Column(DECIMAL(5, 2), default=0)
    completed = Column(Integer, default=0)
    taobao_orders = Column(String(30), default='0')

    def __init__(self):
        self.create_time = int(datetime.now().timestamp())

    @property
    def create_datetime(self):
        if self.create_time:
            return datetime.utcfromtimestamp(self.create_time+28800).strftime("%Y-%m-%d %H:%M:%S")
        else:
            return None